#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-07-13 11:00 上午
# @Author  : yangdy
# @File    : 旋转矩阵
# @Software: PyCharmCE
from typing import List


class Solution:
    def rotate(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        if not matrix:
            return
        n = len(matrix)
        for i in range(n // 2):
            for j in range(n // 2 + n % 2):
                i1, j1 = j, n-1-i
                i2, j2 = n-1-i, n-1-j
                i3, j3 = n-1-j, i
                matrix[i1][j1], matrix[i2][j2], matrix[i3][j3], matrix[i][j] =\
                    matrix[i][j], matrix[i1][j1], matrix[i2][j2], matrix[i3][j3]
        return


solve = Solution()

questions = [
    ([[1, 2, 3], [4, 5, 6], [7, 8, 9]], ),
    ([[5, 1, 9, 11], [2, 4, 8, 10], [13, 3, 6, 7], [15, 14, 12, 16]],),
]

for qi, q in enumerate(questions):
    print(f'#{qi}:', q)
    for qii in q[0]:
        print(qii)
    print('ans:', solve.rotate(q[0]))
    for qii in q[0]:
        print(qii)
